home *** CD-ROM | disk | FTP | other *** search
/ Macromedia Multimedia Showcase 6.0 / Macromedia Multimedia Showcase v6.0 WIN-MAC (XMSH60CD)(Macromedia, Inc.)(1996).iso / pc / demosoft / xres / data.z / RESOURCE.PS < prev    next >
Text File  |  1996-03-29  |  11KB  |  344 lines

  1.  
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. %%                                                                  %%
  4. %% resources.ps:  this file defines the category implementations    %%
  5. %% for the resource categories that are `built in', apart from        %%
  6. %% implicit resources, which are handled internally by the          %%
  7. %% interpreter.  We set the ball rolling by building the            %%
  8. %% implementation dictionary for Category and installing it with    %%
  9. %% initresouces.  After that we can install all the other resource  %%
  10. %% categories without any special trickery.                         %%
  11. %%                                                                  %%
  12. %% Resources are an unforunate grey area between the interpreter's  %%
  13. %% guts and `user-level' PS code.  Some magic must be used to get   %%
  14. %% resources off to a good start.                                   %%
  15. %%                                                                  %%
  16. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  17.  
  18.  
  19. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  20. %%                                                                  %%
  21. %% So here we go.  The implementation of Category is used to create %%
  22. %% new resource categories.  Things are reasonably simple since all %%
  23. %% instances of Category live in global VM.  Implicit resources are %%
  24. %% handled specially by the interpreter and don't actually appear   %%
  25. %% as bona-fide categories with implementation dictionaries.  This  %%
  26. %% will only hurt if people say things like:                        %%
  27. %% /Frog /Filter /Category findresource defineresource              %%
  28. %%                                                                  %%
  29. %% The file names below are UNIX specific.                          %%
  30. %%                                                                  %%
  31. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  32.  
  33. systemdict begin
  34.  
  35. currentglobal
  36. true setglobal
  37.  
  38. <<
  39.   /Category /Category
  40.  
  41.   /InstanceType /dicttype
  42.  
  43.   /DefineResource {
  44.     dup /DefineResource known
  45.     1 index /UndefineResource known and
  46.     1 index /FindResource known and
  47.     1 index /ResourceStatus known and
  48.     1 index /ResourceForAll known and
  49.     1 index /Category known and {
  50.       dup /Instances 8 dict put
  51.       readonly
  52.       Instances 3 -1 roll 2 index put
  53.     } {
  54.       errodict /typecheck get exec
  55.     } ifelse
  56.   }
  57.  
  58.   /UndefineResource {
  59.     dup ResourceStatus {
  60.       pop 2 ne {
  61.         Instances exch undef
  62.       }
  63.     } {
  64.       pop
  65.     } ifelse
  66.   }
  67.  
  68.   /ResourceFileName {
  69.     dup 0 (%resource%Category/) dup length 4 1 roll putinterval
  70.     2 index length
  71.     4 copy getinterval cvs pop
  72.     add 0 exch getinterval exch pop
  73.   }
  74.  
  75.   /FindResource {
  76.     ImplicitInstances 1 index known {
  77.       ImplicitInstances exch get
  78.     } {
  79.       Instances 1 index known not {
  80.         dup 256 string ResourceFileName
  81.         dup status {
  82.           pop pop pop pop 
  83.           currentglobal exch true setglobal
  84.           mark exch {run} stopped cleartomark
  85.           setglobal
  86.         } if
  87.       } if
  88.       Instances 1 index known not {
  89.         errordict /undefinedresource get exec
  90.       } if
  91.       Instances exch get
  92.     } ifelse
  93.   }  
  94.  
  95.   /ResourceStatus {
  96.     ImplicitInstances 1 index known
  97.     Instances 2 index known or {
  98.       pop 0 -1 true
  99.     } {
  100.       256 string ResourceFileName
  101.       dup status {
  102.         pop pop pop pop
  103.         (r) file 256 string readstring pop
  104.         (%%VMusage:) search {
  105.           pop pop 2 exch
  106.           token pop exch token pop exch pop
  107.       2 copy lt {exch} if pop
  108.           true
  109.         } {
  110.           pop 2 -1 true
  111.         } ifelse
  112.       } {
  113.         pop false
  114.       } ifelse
  115.     } ifelse
  116.   }
  117.  
  118.   /ResourceForAll {
  119.     10 dict begin
  120.       /scratch exch def
  121.       /proc exch def
  122.       /template exch def
  123.       ImplicitInstances {
  124.         pop scratch cvs dup template stringmatch {
  125.           /proc load exec
  126.         } {
  127.           pop
  128.         } ifelse
  129.       } forall
  130.       Instances {
  131.         pop scratch cvs dup template stringmatch {
  132.           /proc load exec
  133.         } {
  134.           pop
  135.         } ifelse
  136.       } forall
  137.     end
  138.   }
  139.  
  140.   /ImplicitInstances <<
  141.     /Filter dup
  142.     /ColorSpaceFamily dup
  143.     /Emulator dup
  144.     /IODevice dup
  145.     /ColorRenderingType dup
  146.     /FMapType dup
  147.     /FontType dup
  148.     /FormType dup
  149.     /HalftoneType dup
  150.     /ImageType dup
  151.     /PatternType dup
  152.   >>
  153.  
  154. >> initresources
  155.  
  156. setglobal
  157.  
  158.  
  159. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  160. %%                                                                  %%
  161. %% Now load in the resources that need to be defined in VM.         %%
  162. %%                                                                  %%
  163. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  164.  
  165. /Encoding /Category findresource pop
  166.  
  167.  
  168. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  169. %%                                                                  %%
  170. %% Read in the Encoding resources that the PLRM requires.           %%
  171. %%                                                                  %%
  172. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  173.  
  174. systemdict /StandardEncoding
  175. /StandardEncoding /Encoding findresource put
  176.  
  177. systemdict /ISOLatin1Encoding
  178. /ISOLatin1Encoding /Encoding findresource put
  179.  
  180. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  181. %%                                                                  %%
  182. %% The Distiller device class can recognise standard encodings only %%
  183. %% if they are loaded into memory.  So you should uncomment the     %%
  184. %% following lines if you are using it.                             %%
  185. %%                                                                  %%
  186. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  187.  
  188. /MacRomanEncoding /Encoding findresource pop
  189. /WinAnsiEncoding /Encoding findresource pop
  190.  
  191.  
  192.  
  193. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  194. %%                                                                  %%
  195. %% We want the font category in VM as well.                         %%
  196. %%                                                                  %%
  197. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  198.  
  199. /Font /Category findresource pop
  200.  
  201. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  202. %%                                                                  %%
  203. %% Below here go utility procedures that are at least distantly     %%
  204. %% related to resources.  findencodig and findcharstring are        %%
  205. %% needed for compatibility with old-style composite fonts.         %%
  206. %%                                                                  %%
  207. %% findcolorrendering is as described in the PostScript 2016        %%
  208. %% documentation.                                                   %%
  209. %%                                                                  %%
  210. %% composefont is used to create CID-keyed composite fonts as        %%
  211. %% described in the CID font documentation.                         %%
  212. %%                                                                  %%
  213. %% We also have to redefine findfont as a procedure and not an      %%
  214. %% operator in order to work around a bug in the Adobe printer      %%
  215. %% driver to do with multiple master fonts                          %%
  216. %%                                                                  %%
  217. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  218.  
  219. /findfont {
  220.   findfont
  221. } binddef
  222.  
  223. /findencoding {
  224.   /Encoding findresource
  225. } binddef
  226.  
  227. /findcharstrings {
  228.   /CharStrings findresource
  229. } binddef
  230.  
  231. /findcolorrendering {
  232.   /ColorRendering /ProcSet findresource begin
  233.   10 dict begin
  234.   /origintent exch def
  235.   /intent origintent dup length string cvs def
  236.   /device GetPageDeviceName dup length string cvs def
  237.   /halftone GetHalftoneName dup length string cvs def
  238.   /crd
  239.     intent length device length halftone length add add 2 add
  240.     string def
  241.   crd 0 intent putinterval
  242.   crd intent length 16#2e put
  243.   crd intent length 1 add device putinterval
  244.   crd intent length device length add 1 add 16#2e put
  245.   crd intent length device length add 2 add halftone putinterval
  246.   crd cvn dup /ColorRendering resourcestatus {
  247.     pop pop true
  248.   } {
  249.     pop origintent GetSubstituteCRD false
  250.   } ifelse
  251.   end end
  252. } binddef
  253.  
  254. /composefont {
  255.   16 dict begin
  256.   /FDepVector exch def
  257.   /CMap exch def
  258.   /FontName exch def
  259.   CMap type /nametype eq {
  260.     CMap /CMap findresource
  261.     /CMap exch def
  262.   } if
  263.   CMap /FontMatrices known {
  264.     /FontMatrices CMap /FontMatrices get def
  265.   } {
  266.     /FontMatrices 1 dict def
  267.   } ifelse
  268.   0 1 FDepVector length 1 sub {
  269.     /ind exch def
  270.     FDepVector ind get
  271.     dup type /nametype eq {
  272.       dup /CIDFont resourcestatus {
  273.         pop pop /CIDFont findresource
  274.       } {
  275.         findfont
  276.       } ifelse
  277.     } if
  278.     FontMatrices ind known {
  279.       FontMatrices ind get makefont
  280.     } if
  281.     FDepVector ind 3 -1 roll put
  282.   } for
  283.   /Encoding [ 0 1 FDepVector length 1 sub {} for ] def
  284.   CMap /WMode known {
  285.     /WMode CMap /WMode get def
  286.   } {
  287.     /WMode 0 def
  288.   } ifelse
  289.   /FontType 0 def
  290.   /FMapType 9 def
  291.   /FontMatrix matrix def
  292.   currentdict /ind undef
  293.   currentdict /FontMatrices undef
  294.   FontName currentdict end definefont
  295. } binddef
  296.  
  297.  
  298. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  299. %%                                                                  %%
  300. %% readhexsfnt is a completely undocumented operator that the        %%
  301. %% Windows PostScript driver uses to download a TrueType font.      %%
  302. %% Because it's only used by Windows, it's safe to assume platform  %%
  303. %% equals 2.                                                        %%
  304. %%                                                                  %%
  305. %% We also have readsfntfile for disc-based TrueType fonts. This is %%
  306. %% only used by the TPro resource code.                             %%
  307. %%                                                                  %%
  308. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  309. /readhexsfnt {
  310.   readhexsfnt1
  311.   12 dict begin
  312.   /FontName exch def
  313.   /sfnts exch [ exch ] def
  314.   /Platform 2 def
  315.   /FontMatrix [1 0 0 1 0 0] def
  316.   /FontBBox [-1 -1 1 1] def
  317.   /PaintType 0 def
  318.   /FontType 42 def
  319.   currentdict end
  320. } binddef
  321.  
  322. /readsfntfile {
  323.   readsfntfile1
  324.   12 dict begin
  325.   /FontName exch def
  326.   /sfnts exch def
  327. %% This is messy.  Guess the platform (Mac or Windows) based on the
  328. %% byte order of the host machine...
  329.   /Platform currentsystemparams /ByteOrder get {2} {1} ifelse def
  330.   /FontMatrix [1 0 0 1 0 0] def
  331.   /FontBBox [-1 -1 1 1] def
  332.   /PaintType 0 def
  333.   /FontType 42 def
  334.   currentdict end
  335. } binddef
  336.  
  337. /readCIDsfntfile {
  338.   readsfntfile
  339.   dup /FontType 11 put
  340.   dup /Platform 3 put
  341. } binddef
  342.  
  343. end    % systemdict
  344.